#include <cppunit/config/SourcePrefix.h>
#include "VarTableTest.h"
#include <iostream>
#include <string>

using namespace std;

void
VarTableTest::setUp()
{}
void
VarTableTest::tearDown()
{}

CPPUNIT_TEST_SUITE_REGISTRATION( VarTableTest );

void VarTableTest::testConstructor() 
{
	VarTable* varTable = new VarTable();
	CPPUNIT_ASSERT_EQUAL(varTable->getSize(), 0);
}

void VarTableTest::testInsertVar()
{
	cout << "Testing : INDEX VarTable::insertVar(NAME varName)" << endl;
	VarTable* varTable = new VarTable();
	CPPUNIT_ASSERT_EQUAL(varTable->insertVar("x"), 1);
	CPPUNIT_ASSERT_EQUAL(varTable->insertVar("y"),2);
	CPPUNIT_ASSERT_EQUAL(varTable->insertVar("x"), 1);
	cout << "Test OK  : INDEX VarTable::insertVar(NAME varName)" << endl;
}

void VarTableTest::testGetSize()
{
	cout << "Testing : int VarTable::getSize()" << endl;
	VarTable* varTable = new VarTable();
	varTable->insertVar("x");
	varTable->insertVar("y");
	CPPUNIT_ASSERT_EQUAL(varTable->getSize(),2);
	cout << "Test OK  : int VarTable::getSize()" << endl;
}

void VarTableTest::testGetVarName()
{
	cout << "Testing : NAME VarTable::getVarName(INDEX)" << endl;
	VarTable* varTable = new VarTable();
	//if table is empty
	//CPPUNIT_ASSERT(varTable->getVarName(1) == "NULL", "Invalid value for empty table", 45);

	varTable->insertVar("x");
	varTable->insertVar("y");
	varTable->insertVar("z");
	varTable->insertVar("u");
	CPPUNIT_ASSERT(varTable->getVarName(1) == "x");
	CPPUNIT_ASSERT(varTable->getVarName(2) == "y");
	CPPUNIT_ASSERT(varTable->getVarName(3) == "z");
	CPPUNIT_ASSERT(varTable->getVarName(4) == "u");
	cout << "Test OK  : NAME VarTable::getVarName(INDEX)" << endl;
}

void VarTableTest::testGetVarIndex()
{
	cout << "Testing : INDEX VarTable::getVarIndex(NAME)" << endl;
	VarTable* varTable = new VarTable();
	//if table is empty
	CPPUNIT_ASSERT_EQUAL(varTable->getVarIndex("x"),-1);

	varTable->insertVar("x");
	varTable->insertVar("y");
	varTable->insertVar("z");
	varTable->insertVar("u");
	CPPUNIT_ASSERT_EQUAL(varTable->getVarIndex("x"),1);
	CPPUNIT_ASSERT_EQUAL(varTable->getVarIndex("y"),2);
	CPPUNIT_ASSERT_EQUAL(varTable->getVarIndex("z"),3);
	CPPUNIT_ASSERT_EQUAL(varTable->getVarIndex("u"),4);
	cout << "Test OK  : INDEX VarTable::getVarIndex(NAME)" << endl;
}

/* How to test printing of table?
void VarTableTest::testPrintVarTable()
{
	VarTable* varTable = new VarTable();
	varTable->insertVar("x");
	varTable->insertVar("y");
	varTable->insertVar("z");
	varTable->insertVar("u");
	//CPPUNIT_ASSERT(varTable->printVarTable() != "");
}*/